#define DEBUG
#include <cstdio>
#define MAXN 1000000
#define M0 1610612741
#define M1 2000029
#define SIZE 999983

using namespace std;

int hash1(unsigned long long x) {
  return x%M1;
}

int hash2(unsigned long long x) {
  return M1-x%M1;
}

class HashTable {
public:
  unsigned long long key[SIZE+1];
  int val[SIZE+1];

  int ins(char *s, int v) {
    unsigned long long k=0;
    for (; *s!=' '; s++) {
      k = k*27+*s-'a'+1;
    }

    for (int i=0; i<=SIZE; i++) {
      int pos=(hash1(k)+i*hash2(k))%SIZE;
      if (!key[pos]) {
	key[pos] = k;
	val[pos] = 0;
      }
      if (key[pos]==k) {
	int temp=val[pos];
	val[pos] = v;
	return temp;
      }
    }
    return 0;
  }
};

void read(char *s) {
  for (*s=getchar(); 'a'>*s || 'z'<*s; *s=getchar());
  int i=0;
  do {
    s[++i] = getchar();
  } while(s[i]!='$');
}

int main() {
#ifdef DEBUG
  freopen("2.in", "r", stdin);
  freopen("2.out", "w", stdout);
#endif

  static HashTable ah, bh;
  static char as[MAXN+1], bs[MAXN+1];
  static int a[MAXN+1], b[MAXN+1], p[MAXN+1];
  read(as);
  for (char *i=as; *i!='$'; i++) {
    a[0]++;
    a[a[0]] = a[0]-ah.ins(i, a[0]);
    a[a[0]] = a[a[0]]==a[0] ? 0 : a[a[0]];
    for (; *i!=' '; i++);
  }
  read(bs);
  for (char *i=bs; *i!='$'; i++) {
    b[0]++;
    b[b[0]] = b[0]-bh.ins(i, b[0]);
    b[b[0]] = b[b[0]]==b[0] ? 0 : b[b[0]];
    for (; *i!=' '; i++);
  }

  for (int i=1; i<=b[0]; i++) {
    int x=i-1;
    for (; x; x=p[x]) {
      if ((b[p[x]+1]<=b[i] && !b[p[x]+1]) || b[p[x]+1]==b[i]) {
	p[i] = p[x]+1;
	break;
      }
    }
  }

  for (int i=1, j=1; i<=a[0]; i++, j++) {
    for (; j; j=p[j]) {
      if ((j<=a[i] && !b[j]) || b[j]==a[i]) {
	break;
      }
    }
    if (j==b[0]) {
      printf("%d", i-b[0]+1);
      return 0;
    }
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
